home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / patch3.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  6KB  |  209 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  PATCH3.H - 3-D Patch Classes
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _PATCH3_H
  39. #define _PATCH3_H
  40.  
  41. #include "vector3.h"
  42. #include "color.h"
  43.  
  44. #define QUAD_FLAG   0x01    // Quadrilateral flag
  45.  
  46. class Surface3;             // External reference
  47.  
  48. class ElemList              // Element list
  49. {
  50.   private:
  51.     class Element3 *pelem;  // Element pointer
  52.     ElemList *pnext;        // Next element list pointer
  53.  
  54.   public:
  55.     ElemList( Element3 *pe, ElemList *pel )
  56.     { pelem = pe; pnext = pel; }
  57.  
  58.     Element3 *GetElemPtr() { return pelem; }
  59.     ElemList *GetNext() { return pnext; }
  60. };
  61.  
  62. class PatchList             // Patch list
  63. {
  64.   private:
  65.     class Patch3 *ppatch;   // Patch pointer
  66.     PatchList *pnext;       // Next patch list pointer
  67.  
  68.   public:
  69.     PatchList( Patch3 *pp, PatchList *ppl )
  70.     { ppatch = pp; pnext = ppl; }
  71.  
  72.     Patch3 *GetPatchPtr() { return ppatch; }
  73.     PatchList *GetNext() { return pnext; }
  74. };
  75.  
  76. class Vertex3           // 3-D vertex
  77. {
  78.   private:
  79.     Point3 posn;        // Vertex co-ordinates
  80.     Vector3 normal;     // Vertex normal
  81.     Spectra exitance;   // Vertex exitance
  82.     ElemList *pelhd;    // Element list head pointer
  83.     Vertex3 *pnext;     // Next vertex pointer
  84.  
  85.   public:
  86.     Vertex3( Point3 &coord )
  87.     {
  88.       posn = coord;
  89.       normal = 0.0;
  90.       pelhd = NULL;
  91.       pnext = NULL;
  92.       exitance.Reset();
  93.     }
  94.  
  95.     ~Vertex3()
  96.     {
  97.       ElemList *pel = pelhd;
  98.       ElemList *pelnext;
  99.  
  100.       // Delete element list
  101.       while (pel != NULL)
  102.       {
  103.         pelnext = pel->GetNext();
  104.         delete pel;
  105.         pel = pelnext;
  106.       }
  107.     }
  108.  
  109.     ElemList *GetElemListPtr() { return pelhd; }
  110.     Point3 &GetPosn() { return posn; }
  111.     Point3 *GetPosnPtr() { return &posn; }
  112.     Spectra &GetExitance() { return exitance; }
  113.     Vector3 &GetNormal() { return normal; }
  114.     Vertex3 *GetNext() { return pnext; }
  115.     void CalcNormal();
  116.     void SetExitance( Spectra &e ) { exitance = e; }
  117.     void SetElemListPtr( ElemList *ppl) { pelhd = ppl; }
  118.     void SetNext( Vertex3 *pn ) { pnext = pn; }
  119.     void SetPosn( Point3 &p ) { posn = p; }
  120. };
  121.  
  122. class Element3                  // 3-D element
  123. {
  124.   protected:
  125.     BYTE flags;                 // Flags bitmap
  126.     float area;                 // Element area
  127.     Patch3 *ppatch;             // Parent patch pointer
  128.     Spectra exitance;           // Spectral exitance
  129.     Vector3 normal;             // Normal vector
  130.     Vertex3 *pvertex[4];        // Vertex pointer array
  131.     Element3 *pnext;            // Next element pointer
  132.  
  133.   public:
  134.     Element3( Vertex3 *pvtx[4], Patch3 *pp )
  135.     {
  136.       int index;        // Array index
  137.  
  138.       ppatch = pp;
  139.       area = (float)0.0;
  140.       flags = (BYTE) 0;
  141.       pnext = NULL;
  142.       exitance.Reset();
  143.  
  144.       for (index = 0; index < 4; index++)
  145.         pvertex[index] = pvtx[index];
  146.     }
  147.  
  148.     BOOL IsQuad() { return (flags & QUAD_FLAG); }
  149.     double GetArea() { return area; }
  150.     int GetNumVert()
  151.     { return (flags & QUAD_FLAG) ? 4 : 3; }
  152.     Element3 *GetNext() { return pnext; }
  153.     Patch3 *GetParentPtr() { return ppatch; }
  154.     Spectra &GetExitance() { return exitance; }
  155.     Vector3 &GetNormal() { return normal; }
  156.     Vertex3 *GetVertexPtr( int i ) { return pvertex[i]; }
  157.     void CalcArea();
  158.     void CalcNormal();
  159.     void SetExitance( Spectra &e ) { exitance = e; }
  160.     void SetNext( Element3 *pn ) { pnext = pn; }
  161.     void SetQuad() { flags |= QUAD_FLAG; }
  162. };
  163.  
  164. class Patch3 : public Element3  // 3-D patch
  165. {
  166.   private:
  167.     Point3 center;      // Patch center
  168.     Element3 *pelhd;    // Element list head ptr
  169.     Surface3 *psurf;    // Parent surface pointer
  170.  
  171.   public:
  172.     Patch3( Vertex3 *pvtx[4], Surface3 *ps ) :
  173.         Element3( pvtx, NULL )
  174.     {
  175.       pelhd = NULL;
  176.       psurf = ps;
  177.     }
  178.  
  179.     ~Patch3()
  180.     {
  181.       Element3 *pe = pelhd;
  182.       Element3 *penext;
  183.  
  184.       while (pe != NULL)        // Delete elements
  185.       {
  186.         penext = pe->GetNext();
  187.         delete pe;
  188.         pe = penext;
  189.       }
  190.     }
  191.  
  192.     double GetUnsentFlux()
  193.     {
  194.       return ((exitance.GetRedBand() +
  195.           exitance.GetGreenBand() + exitance.GetBlueBand())
  196.           * (double) area);
  197.     }
  198.  
  199.     Element3 *GetElementPtr() { return pelhd; }
  200.     Patch3 *GetNext() { return (Patch3 *) pnext; }
  201.     Point3 &GetCenter() { return center; }
  202.     Surface3 *GetParentPtr() { return psurf; }
  203.     void CalcCenter();
  204.     void SetElementPtr( Element3 *pe ) { pelhd = pe; }
  205. };
  206.  
  207. #endif
  208.  
  209.